package com.freewater.springboot.demo.aop.example;


import org.springframework.dao.PessimisticLockingFailureException;
import org.springframework.transaction.annotation.Transactional;

import java.util.Random;

@Transactional
public class SomeBusinessService {

    @Idempotent
    public void doSomeBusiness() {
        System.out.println("do something...");
        Random random = new Random();
        int randNum = random.nextInt(10);
        if (randNum % 2 == 0) {
            throw new PessimisticLockingFailureException("test pessimistic lock");
        }
    }

    public void doOtherBusiness() {
        System.out.println("do other thing...");
    }
}
